package com.robot.mvvm.vm.work

import android.app.Application
import api.IotServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.model.BaseListBean
import com.robot.base.model.QuestionLogDTOBean
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent
import me.goldze.mvvmhabit.http.BaseResponse

class RepairWorkOrderScheduleViewModel(application: Application) : GLBaseViewModel(application) {

    val uc = UiChangeEvent()

    class UiChangeEvent {
        val refreshDataEvent = SingleLiveEvent<List<QuestionLogDTOBean>>()
    }

    fun getLogListByQuestionId(questionId: String) {
        IotServiceFactory.getLogListByQuestionId(
            mapOf(
                "questionId" to questionId
            )
        ).subscribe(
            object : AbstractViewModelSubscriber<BaseResponse<BaseListBean<QuestionLogDTOBean>>>(this) {
                override fun onNext(t: BaseResponse<BaseListBean<QuestionLogDTOBean>>) {
                    uc.refreshDataEvent.postValue(t.data.list)
                }
            }
        )
    }
}